//
//  AFNetworkingManager.m
//  SkinerZTZ
//
//  Created by cts on 2018/1/11.
//  Copyright © 2018年 hhjiang. All rights reserved.
//

#import "AFNetworkingManager.h"

@implementation AFNetworkingManager
/**
 单例创建对象
 
 @return HANetworking对象
 */
+ (instancetype)sharedInstance
{
    static AFNetworkingManager *netWorking = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        netWorking = [[AFNetworkingManager alloc]init];
    });
    return netWorking;
}

- (void)POSTDaTa:(NSString *)URLString parameters:(NSDictionary *)dic Withsuccess:(Success1)success WithFailure:(Failure1)failure{
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"application/x-json",@"text/html", nil];
    [manager POST:URLString parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        // 上传图片，以文件流的格式，这里注意：name是指服务器端的文件夹名字
        // [formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/jpeg"];
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //上传成功时的回调
        success(responseObject);
     NSLog(@"responseObject = %@",responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure(error);
        NSLog(@"error = %@",error);
    }];
    
    
    
}


- (void)GET:(NSString *)URLString parameters:(NSDictionary *)dic Withsuccess:(Success1)success WithFailure:(Failure1)failure{
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"application/x-json",@"text/html", nil];
    [manager GET:URLString parameters:dic success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        success(responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failure(error);
        
    }];
    
}

- (void)POST:(NSString *)URLString parameters:(NSDictionary *)dic Withsuccess:(Success1)success WithFailure:(Failure1)failure{
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"application/x-json",@"text/html", nil];
    [manager POST:URLString parameters:dic success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        success(responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failure(error);
        
    }];
}



@end
